package com.zhangtai.modules.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhangtai.modules.dto.InsuranceChangeDto;
import com.zhangtai.modules.dto.InsuranceMemberRecordDto;
import com.zhangtai.modules.dto.SecurityMemberChangeListDto;
import com.zhangtai.modules.entity.insurance.InsuranceChangeEntity;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-11-23 14:28:02
 */
@Mapper
public interface InsuranceChangeDao extends BaseMapper<InsuranceChangeEntity> {

    @Select("<script>select t1.operation_time,t1.operate_name,t1.operater_code,t2.code,t2.name,t2.gender,t2.job_type,t2.employeestatus,t2.job_level_id," +
            "t2.hiredate,t2.job_id,t2.org_id,t2.unit_id,t1.type,case t4.security_id when t4.security_id  then 1 else 0 end security_type,t2.idcard,t3.company_name " +
            " from ( select oid,type,count(oid) count,insurance_id,max(operation_time) operation_time,operate_name,operater_code,unit_id,org_id from tb_insurance_change " +
            "where  (type =1 or type =0) and is_delete = 0 " +
            "<if test='startTime !=null and startTime !=&apos;&apos;'>and operation_time &gt;= '${startTime} 00:00:00'</if> " +
            "<if test='endTime !=null and endTime !=&apos;&apos;'>and operation_time &lt;= '${endTime} 23:59:59' </if> " +
            "<if test='operateName !=null and operateName!=&apos;&apos;'> and operate_name like '%${operateName}%'</if>"+
            "group by oid,insurance_id,unit_id ) t1" +
            " left join tb_employee_info t2 on t1.oid = t2.oid " +
            " left join tb_insurance t3 on t3.id = t1.insurance_id " +
            " left join tb_employee_security t4 on t1.oid = t4.oid " +
            "<where> t1.count%2>0 " +
            "<if test='orgIds!=null and orgIds.size>0'> and  t1.unit_id in " +
            " <foreach item=\"orgId\" index=\"index\" collection=\"orgIds\" open=\"(\" separator=\",\" close=\")\">#{orgId}</foreach>" +
            "</if>"+
            "<if test='orgIds==null or orgIds.size==0'> and t1.unit_id = null  </if> " +
            "<if test='orgId!=null and orgId.size>0'> and  t1.org_id in " +
            " <foreach item=\"orgId\" index=\"index\" collection=\"orgId\" open=\"(\" separator=\",\" close=\")\">#{orgId}</foreach>" +
            "</if>" +
            "<if test='orgId!=null and orgId.size ==0'> and t1.org_id = null </if>" +
            "<if test='companyName !=null and companyName!=&apos;&apos;'> and t3.companyName like '%${companyName}%' </if>"+
            "<if test='employeestatus !=null and employeestatus!=&apos;&apos;'> and t2.employeestatus = #{employeestatus}</if>"+
            "<if test='status !=null and status == 0'> and t4.security_id is null </if>"+
            "<if test='type !=null '> and t1.type = #{type}</if>"+
            "<if test='status !=null and status == 1'> and t4.security_id is not null </if>"+
            "</where>"+
            " order by t1.operation_time desc </script>" )
    List<InsuranceChangeDto> getMemberChangeList(@Param("orgIds")List<Long> orgIds,@Param("startTime")String startTime,@Param("endTime")String endTime,
                                                 @Param("companyName")String companyName,@Param("employeestatus")String employeestatus,@Param("type") Integer type,
                                                 @Param("status")Integer status,@Param("operateName")String operateName, @Param("orgId")List<Long> orgId,IPage<InsuranceChangeDto>page);



}
